*********************************************************************************************
*  	Created By:	   	Richard Saunders & Mark Souva					    					*
*  	Creation Date: 	10/8/2020                                                				*                           	
*  	Purpose:    	Replication of "Air Superiority and Military Victory" Appendix material	*                                                    	    
*  	Data Input:    	"SS_airvictory.dta"		                            					*        	
*    	            											 			 				*								      	
*********************************************************************************************


*************************
*** Appendix Material ***
*************************


***CAP2 Correlation***

use "SS_airvictory.dta", clear


merge 1:1 ccode warname battlename using "GH_CAP2", keepusing(cap2share)

cor cap2share airsup

drop if win ==.
drop if airsup == .
drop if cap2share == .
 
egen maxcap = max(cap2share), by(battlename)
egen mincap = min(cap2share), by(battlename)


* S&S 2019 provides no expectation about how far superior one side must be in their CAP2 measure to be expected to win air superiority rather than parity.*
* We assume a 25% advantage or more is needed for purposes of this comparison.*
gen sup = .
replace sup = 1 if maxcap > mincap*1.25
gen par = .
replace par = 1 if sup == .

gen EAS = 0
replace EAS = 2 if cap2share == maxcap & sup ==1
replace EAS = 1 if par == 1

*drop combatants provided airsup by a stronger ally*
drop if ccode == 500 & battlename == "Battle for Entebbe, Apr 1979"
drop if ccode == 490 & battlename == "December Offensive"
drop if ccode == 200 & battlename == "Operation Anaconda"
drop if ccode == 200 & battlename == "Operation Iraqi Freedom"
drop if ccode == 900 & battlename == "Operation Iraqi Freedom"
drop if ccode == 530 & battlename == "Second Battle of Jijiga, Feb 1978"



tab EAS airsup, chi2 exp
cor EAS airsup if airsup !=1 & EAS != 1



*****Loss exchange ratio*****

**Manual generation of merge variables between G&H and B&L**


*Biddle & Long*
use "BiddleLongJCR04.dta", clear

gen warname = ""
gen battlename = ""
gen attacker = ""
gen defender = ""

drop if date < 1932

replace warname = "Changkufeng" if campn == "CHANGKUFENG" & engagem == "HILL 52-SHACHAOFENG" | engagem == "CHANGKUFENG-HILL 52"
replace battlename = "Changkufeng Hill" if campn == "CHANGKUFENG" & engagem == "HILL 52-SHACHAOFENG" | engagem == "CHANGKUFENG-HILL 52"
replace attacker = "Russia" if ru_atk == 1
replace attacker = "Japan" if ja_atk == 1
replace defender = "Russia" if ru_def ==1
replace defender = "Japan" if ja_def ==1

replace warname = "Nomohan1939" if campn == "NOMONHAN" & engagem == "NOMONHAN-SOVIET COUNTEROFFENSIVE"
replace battlename = "Soviet Counteroffensive, Aug 20 1939" if campn == "NOMONHAN" & engagem == "NOMONHAN-SOVIET COUNTEROFFENSIVE"
replace attacker =  "Russia" if ru_atk == 1
replace attacker =  "Japan" if ja_atk == 1
replace defender =  "Russia" if ru_def ==1
replace defender =  "Japan" if ja_def ==1

replace warname = "UnitedKingdom/UnitedStates-Germany/Italy1940-1945" if engagem == "OPERATION COBRA"
replace battlename = "Operation Cobra" if engagem == "OPERATION COBRA"
replace attacker =  "United States" if us_atk == 1
replace attacker =  "Germany" if ge_atk == 1
replace defender =  "United States" if us_def ==1
replace defender =  "Germany" if ge_def ==1

replace warname = "UnitedKingdom/UnitedStates-Germany/Italy1940-1945" if campn == "CASSINO"
replace battlename =  "Operation Diadem (Gustav Line Breakout, May 11-18)" if campn == "CASSINO"
replace attacker =  "United States" if us_atk == 1
replace attacker =  "Germany" if ge_atk == 1
replace defender =  "United States" if us_def ==1
replace defender =  "Germany" if ge_def ==1

replace warname =  "SixDay1967" if campn == "SINAI"
replace battlename = "Sinai (Northern)"  if campn == "SINAI"
replace attacker =  "Israel" if is_atk == 1
replace attacker =  "Egypt" if eg_atk == 1
replace defender =  "Egypt" if eg_def ==1
replace defender =  "Israel" if is_def ==1

replace warname =  "SixDay1967" if campn == "WEST BANK"
replace battlename = "Samaria"  if campn == "WEST BANK"
replace attacker =  "Israel" if is_atk == 1
replace attacker =  "Jordan" if jo_atk == 1
replace defender =  "Jordan" if jo_def ==1
replace defender =  "Israel" if is_def ==1

replace warname =  "SixDay1967" if campn == "GOLAN"
replace battlename = "Northern Golan"  if campn == "GOLAN"
replace attacker =  "Israel" if is_atk == 1
replace attacker =  "Syria" if sy_atk == 1
replace defender =  "Syria" if sy_def ==1
replace defender =  "Israel" if is_def ==1

replace warname =  "YomKippurI1973" if campn == "GOLAN"
replace battlename = "Contained offensive, Oct 14"  if engagem == "EGYPTIAN OFFENSIVE, NORTH" | engagem == "EGYPTIAN OFFENSIVE, SOUTH"
replace attacker =  "Israel" if is_atk == 1
replace attacker =  "Egypt" if eg_atk == 1
replace defender =  "Egypt" if eg_def ==1
replace defender =  "Israel" if is_def ==1

replace warname =  "YomKippurI1973" if campn == "GOLAN" 
replace battlename = "Southern Golan"  if engagem == "RAFID" | engagem == "TEL FARRIS" | engagem == "YEHUDA-EL AL" | engagem == "NAFEKH"  | engagem == "HUSHNIYAH" 
replace attacker =  "Israel" if is_atk == 1
replace attacker =  "Syria" if sy_atk == 1
replace defender =  "Syria" if sy_def ==1
replace defender =  "Israel" if is_def ==1

replace warname =  "Palestine1948-1949" if campn == "HIRAM" 
replace battlename = "Operation Hiram (Oct 20-31)"  if campn == "HIRAM" 
replace attacker =  "Israel" if is_atk == 1
replace attacker =  "Syria" if sy_atk == 1
replace defender =  "Syria" if sy_def ==1
replace defender =  "Israel" if is_def ==1

replace warname =  "Palestine1948-1949" if campn == "JERUSALEM CORRIDOR" 
replace battlename = "Jerusalem Corridor (July)"  if campn == "JERUSALEM CORRIDOR" 
replace attacker =  "Israel" if is_atk == 1
replace attacker =  "Jordan" if jo_atk == 1
replace defender =  "Jordan" if jo_def ==1
replace defender =  "Israel" if is_def ==1

replace warname =  "Palestine1948-1949" if campn == "EL AUJA (AYIN)" | campn == "AGEILA-RAFAH (AYIN)"
replace battlename = "Operation Horev (Late December)"  if campn == "EL AUJA (AYIN)" | campn == "AGEILA-RAFAH (AYIN)"
replace attacker =  "Israel" if is_atk == 1
replace attacker =  "Egypt" if eg_atk == 1
replace defender =  "Egypt" if eg_def ==1
replace defender =  "Israel" if is_def ==1


replace warname =  "Sinai1956" if war == "ARAB-ISRAELI, 1956"
replace battlename = "Sinai"  if war == "ARAB-ISRAELI, 1956"
replace attacker =  "Israel" if is_atk == 1
replace attacker =  "Egypt" if eg_atk == 1
replace defender =  "Egypt" if eg_def ==1
replace defender =  "Israel" if is_def ==1

replace warname =  "Israeli-Syria(Lebenon)1982" if war == "ISRAEL-LEBANON, 1982"
replace battlename = "Peace for Galilee"  if war == "ISRAEL-LEBANON, 1982"
replace attacker =  "Israel" if is_atk == 1
replace attacker =  "Syria" if sy_atk == 1
replace defender =  "Syria" if sy_def ==1
replace defender =  "Israel" if is_def ==1

replace warname =  "Germany-SovietUnion1941-1945" if campn == "MOSCOW COUNTEROFFENSIVE"
replace battlename = "Winter Counteroffensive, Dec 1941 - Jan 1942"  if campn == "MOSCOW COUNTEROFFENSIVE"
replace attacker =  "Russia" if ru_atk == 1
replace attacker =  "Germany" if ge_atk == 1
replace defender =  "Germany" if ge_def ==1
replace defender =  "Russia" if ru_def ==1

rename attacker Country

gen Year = floor(date)
do "C:\Users\saund\Dropbox\Saunders and Souva\Airpower and Victory docs\Grauer and Horowtiz data\Grauer and Horowitz\country name to cowcode do file.do"

rename cowcode ccode1

rename Country attacker

rename defender Country
do "C:\Users\saund\Dropbox\Saunders and Souva\Airpower and Victory docs\Grauer and Horowtiz data\Grauer and Horowitz\country name to cowcode do file.do"

rename cowcode ccode2

egen tot_attackercas = total(acas_per), by(warname battlename)
egen tot_defendercas = total(dcas_per), by(warname battlename)

duplicates drop battlename warname, force

save "B&L_LER.dta", replace


*LERD dataset*

use "Battle Level Data.dta", clear

replace warname = "Germany-Poland1939" if warname == "World War II, Poland"
replace battlename = "September Campaign, Silesian Breakthrough" if battlename == "Polish Blitzkrieg, Germany"

replace warname = "Germany-France1939" if warname == "World War II, France"
replace battlename = "Battle for France, June 5 - 22, 1940" if battlename == "Battle of France"

replace warname = "Germany-Greece1941" if warname == "World War II, Germany vs Greece"
replace battlename = "April 6-9 Offensive, Metaxas Line" if battlename == "German Attack on Greece"

replace warname = "Japan-UnitedStates1941-1945" if warname == "World War II, Pacific Front"
replace battlename = "Guadalcanal (Henderson Field Oct 23-6)" if battlename == "Guadalcanal, Oct 23"

replace warname = "Korean War" if warname == "Korea"
replace battlename = "Invasion over 38th Parallel" if battlename == "Osan" 

replace warname = "Korean War" if warname == "Korea"
replace battlename = "Inchon-Seoul Campaign" if battlename == "Blue Beach" | battlename == "In'chon Landing" | battlename == "Wolmi-do" 

rename accode1 ccode1
rename bccode1 ccode2

egen tot_casualtiesA = total(casualtiesA), by(warname battlename ccode1)
egen tot_casualtiesB = total(casualtiesB), by(warname battlename ccode2)

duplicates drop battlename warname, force


save "LERD_LER.dta", replace


use "SS_airvictory.dta", clear

rename ccode ccode1

merge 1:1 battlename warname ccode1 using "B&L_LER.dta", keepusing(tot_attackercas tot_defendercas)
drop if _merge ==2
gen Attack = 1 if _merge ==3
drop _merge

gen LER1 = tot_attackercas/tot_defendercas

rename ccode1 ccode2

merge 1:1 battlename warname ccode2 using "B&L_LER.dta", keepusing(tot_attackercas tot_defendercas) update

drop if _merge ==2
gen Defend = 1 if _merge ==4
drop _merge


gen LER2 = tot_defendercas/tot_attackercas

gen BL_LER = .
replace BL_LER = LER1 if Attack ==1
replace BL_LER = LER2 if Defend ==1

drop LER1 LER2 Attack Defend


rename ccode2 ccode1
merge 1:1 battlename warname ccode1 using "LERD_LER.dta", keepusing(tot_casualtiesA tot_casualtiesB)

drop if _merge ==2
gen Attack = 1 if _merge ==3
drop _merge

gen LER1 = tot_casualtiesA/tot_casualtiesB

rename ccode1 ccode2


merge 1:1 battlename warname ccode2 using "LERD_LER.dta", keepusing(tot_casualtiesA tot_casualtiesB) update

drop if _merge ==2
gen Defend = 1 if _merge ==4
drop _merge


gen LER2 = tot_casualtiesB/tot_casualtiesA

gen LERD_LER = .
replace LERD_LER = LER1 if Attack ==1
replace LERD_LER = LER2 if Defend ==1

drop LER1 LER2 Attack Defend

gen combined_LER = .
replace combined_LER = BL_LER if BL_LER !=.
replace combined_LER = LERD_LER if LERD_LER !=.


gen d6 = 0 
replace d6 = 1 if polity >= 17 & polity !=.
replace d6 = . if polity == .

gen anoc12 = 1 if polity > 5 & polity < 17 & polity !=.
replace anoc12 = 0 if anoc12 == . & polity != .

eststo clear


reg combined_LER airsup_alt polity cinc bankscoups, cluster(ccode)
eststo
reg combined_LER msadopt polity cinc  bankscoups, cluster(ccode)
eststo
reg combined_LER airsup_alt msadopt polity cinc  bankscoups, cluster(ccode)
eststo

esttab using "LERAppendixTable.tex", label cells("b(star fmt(3))" se(par)) nobaselevels  replace starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) title(Regression table\label{tab1})


*Air superiority reduces own casualties by 1.5ish per enemy killed*
